// pages/my_collect/my_collect.js
const request = require('../../utils/request.js')
const config = require('../../config.js');
import { getCollectList } from '../../static/api/api.js'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        listData:null,
        isNoMore: false,
        pageLoad:false,
        curStatus:10,
        pages: {
            curPage: 1,
            totalPage: 1
        },
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getCollectList()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    lower:function(){
        this.getCollectList()
    },
    getCollectList() {
        if (this.data.pageLoad) return;
        if (this.data.pages.curPage > this.data.pages.totalPage) return;
        this.setData({
            pageLoad: true
        })
    
        let that = this;
        let poi = wx.getStorageSync('locationData')
        let params = {
            longitude:poi.poi.location.lng,
            latitude: poi.poi.location.lat,
            behavior: this.data.curStatus,
            page: this.data.pages.curPage
        }
        getCollectList(params).then(response => {
            console.log(response.data)
            let data = response.data;
            if (that.data.pages.curPage == 1) {
                that.setData({
                    listData: data.lists
                })
            } else {
                that.setData({
                    listData: that.data.listData.concat(data.lists)
                })
            }
            that.setData({
                'pages.curPage': that.data.pages.curPage + 1,
                'pages.totalPage': data.page.total_page,
                'pageLoad': false
            })
            if (this.data.pages.curPage >= this.data.pages.totalPage) {
                this.setData({
                    isNoMore: true
                })
            };
        }).catch(response => {
            that.setData({
                'pageLoad': false
            })
        })

    },
    changeCatgory(e) {
        let dataset = e.currentTarget.dataset;
        this.setData({
            curStatus: dataset.status,
            'pages.curPage': 1,
            'pages.totalPage': 1,
            'pageLoad': false,
            'isNoMore': false,
            'listData': null
        })
        this.getCollectList()
    },
})